/**
 * 
 */
package soa.security.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.springframework.ldap.odm.annotations.Attribute;
import org.springframework.ldap.odm.annotations.DnAttribute;
import org.springframework.ldap.odm.annotations.Entry;
import org.springframework.ldap.odm.annotations.Id;
import org.springframework.ldap.support.LdapNameBuilder;
import soa.security.Constants;

import javax.naming.Name;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @author CreGu
 *
 */
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@Entry(objectClasses = { "zjtzsw-department", "zjtzsw-bid" })
public final class Department extends SoaBid {

	private static final long serialVersionUID = -8776603516855560484L;

	@XmlTransient
	@JsonIgnore
	@Id
	private Name dn;

	@DnAttribute(value = "bid")
	private String bid;

	private String parentBid;

	@Attribute(name = "ou")
	private String name;

	private String ename;

	private String aliasName;
	
	private String regionCode;

	private String gradeCode;

	@Deprecated
	private String departmentType;

	private String zipCode;

	private String departmentAddress;

	@Attribute(name = "telephoneNumber")
	private String departmentPhone;

	private String departmentFax;

	private String departmentLeader;

	private String establishData;

	private String description;

	private int priority;

	private String createTime;
	
	private String persons;

	public Department() {
	}

	public Department(String bid, String name) {
		super();
		this.bid = bid;
		this.name = name;
	}

	public static Department build(String bid, String name) {
		return new Department(bid, name);
	}

	public static Department build(String bid, String name, String parentBid) {
		Department department = new Department(bid, name);
		department.setParentBid(parentBid);
		return department;
	}
	
	public static Department buildGradeCode(String bid, String name, String gradeCode) {
		Department department = new Department(bid, name);
		department.setGradeCode(gradeCode);
		return department;
	}
	
	public static Department build(String bid, String name, String parentBid, String gradeCode) {
		Department department = new Department(bid, name);
		department.setParentBid(parentBid);
		department.setGradeCode(gradeCode);
		return department;
	}

	public Name buildDn(Name baseDn) {
		return LdapNameBuilder.newInstance(baseDn).add(Constants.BID, getBid())
				.build();
	}

	public Name getDn() {
		return dn;
	}

	public void setDn(Name dn) {
		this.dn = dn;
	}

	public String getBid() {
		return bid;
	}

	public void setBid(String bid) {
		this.bid = bid;
	}

	public String getParentBid() {
		return parentBid;
	}

	public void setParentBid(String parentBid) {
		this.parentBid = parentBid;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getEname() {
		return ename;
	}

	public void setEname(String ename) {
		this.ename = ename;
	}

	public String getAliasName() {
		return aliasName;
	}

	public void setAliasName(String aliasName) {
		this.aliasName = aliasName;
	}

	public String getGradeCode() {
		return gradeCode;
	}

	public void setGradeCode(String gradeCode) {
		this.gradeCode = gradeCode;
	}

	public String getDepartmentType() {
		return departmentType;
	}

	public void setDepartmentType(String departmentType) {
		this.departmentType = departmentType;
	}

	public String getZipCode() {
		return zipCode;
	}

	public void setZipCode(String zipCode) {
		this.zipCode = zipCode;
	}

	public String getDepartmentAddress() {
		return departmentAddress;
	}

	public void setDepartmentAddress(String departmentAddress) {
		this.departmentAddress = departmentAddress;
	}

	public String getDepartmentPhone() {
		return departmentPhone;
	}

	public void setDepartmentPhone(String departmentPhone) {
		this.departmentPhone = departmentPhone;
	}

	public String getDepartmentFax() {
		return departmentFax;
	}

	public void setDepartmentFax(String departmentFax) {
		this.departmentFax = departmentFax;
	}

	public String getDepartmentLeader() {
		return departmentLeader;
	}

	public void setDepartmentLeader(String departmentLeader) {
		this.departmentLeader = departmentLeader;
	}

	public String getEstablishData() {
		return establishData;
	}

	public void setEstablishData(String establishData) {
		this.establishData = establishData;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public int getPriority() {
		return priority;
	}

	public void setPriority(int priority) {
		this.priority = priority;
	}

	public String getCreateTime() {
		return createTime;
	}

	public void setCreateTime(String createTime) {
		this.createTime = createTime;
	}

	public String getRegionCode() {
		return regionCode;
	}

	public void setRegionCode(String regionCode) {
		this.regionCode = regionCode;
	}


	@XmlRootElement
	@XmlAccessorType(XmlAccessType.FIELD)
	public static class Departments {
		protected List<Department> department = new ArrayList<Department>();

		public List<Department> getDepartment() {
			return this.department;
		}

		public void addDepartment(Department department) {
			this.department.add(department);
		}

		public boolean addAll(Collection<? extends Department> c) {
			return department.addAll(c);
		}

	}
}
